import React from 'react'
import Top from '../components/top'
import '../assets/css/login.css'
import {getLogin} from '../request/app'
class Home extends React.Component{
constructor(){
super()
this.state={
    user:{
        phone:'',
        password:""
    }
}
}
chanond(type,e){
    console.log(type);
    this.setState({
        user:{
            ...this.state.user,
            [type]:e.target.value
        }
    })

}

denlu(){
    // 判空
    if(
        this.state.user.phone ==="" ||
         this.state.user.password ==="" ){
        alert('关键内容不能为空')
        return;
    }
    // 判断手机号码格式
    let str = /^1[3-9]\d{9}$/;

    if(!str.test(this.state.user.phone)){
        alert('手机号格式不对')
        return;
    }
    // 调用接口
    getLogin(this.state.user).then(res=>{
        console.log(res);
        if(res.code==500){
            alert('手机号未注册，请输入正确手机号')
            return
        }else{
            sessionStorage.setItem('xiaou', JSON.stringify(res.list))
            alert(res.msg)
            // open('/index/home')
            window.open('/index/home')
            return
        }
        
    })
}
 cz(){
        window.open('/register')
    }

render(){
  
   
return (<div className='mylogin'>
     <div className='top'>
         <Top/>
         <div className='top_om'>
             {/* 点击事件 */}
             <div>&lt;</div>
             <div>手机登录</div>
             <div>13</div>
         </div>
         
         
    </div>

    {/*  */}
    <div className='
    center'>
        <div className='img'>
            <img src={require('../assets/img/u选.png')} alt="" />

        </div>
        {/*  */}
        <div className='int'>
              <div className='sjh'>
            <input onChange={this.chanond.bind(this,'phone')} type="text" placeholder='手机号'/>
        </div>
              <div className='text'>
            <input onChange={this.chanond.bind(this,'password')} type="text" placeholder='密码'/> 
        </div>
             
        </div>
        <div className='cz'>
            <p>未注册？<span onClick={this.cz.bind()}>去注册</span></p>
        </div>
      {/*  */}
      
      <div className='btn'>
          <button onClick={this.denlu.bind(this)}>登录</button>
      </div>

    </div>
</div>)
}
}
export default Home